/************************************************************************************
 RC Hobby Stream
 Twitter automatic feeder

 First version developed with support of Mapelgate Media

"RC Hobby Stream" is protected by the copyright law
© 2011 Enrico Miglino / Tech Consulting (enrico.miglino@ovi.com)
Distributed under the LGPL 3.0 license.

This file is part of "RC Hobby Stream".

    "RC Hobby Stream" is free software: you can redistribute it
    and/or modify it under the terms of the Lesser GNU General Public License
    as published by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    "RC Hobby Stream" is distributed in the hope that it
    will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    Lesser GNU General Public License for more details.

    You should have received a copy of the Lesser GNU General Public License
    along with "RC Hobby Stream".
    If not, see <http://www.gnu.org/licenses/>.
************************************************************************************/

import Qt 4.7

// Wrapper used to manage the twitter messages through xml delivered from twitter.com
Item { id: wrapper
    // Property used to manage tweet search and retrieved data.
    property variant model: xmlModel    // Data model
    // Search string for tweets
    property string from : "q=from:Flyrcmag OR from:Rcdriverguys OR from:Robot_magazine OR from:Rcgroupbuy OR from:rchelipilot"

    property int status: xmlModel.status

    /*  reload()
        Reload the search for twitter updates based on the xml model.
    */
    function reload() {
        xmlModel.reload();
    }

    // Elements and relative behaviors for the xml model that reflects the xml data
    // delivered by twitter through the api. For every tweet, all data are delivered by
    // the site in a xml format.
    XmlListModel {
        id: xmlModel    // Definition of the content for the tweet list.
                        // The model uses tweets search parameters and twitter api

        // Html source string for the search
        source: 'http://search.twitter.com/search.atom?' + from
        // Definition of twitter name space (based on twitter api)
        namespaceDeclarations: "declare default element namespace 'http://www.w3.org/2005/Atom'; " +
                               "declare namespace twitter=\"http://api.twitter.com/\";";
        // Query execution web path
        query: "/feed/entry"

        // Definition of xml roles. The roles rflects the data that should be used for
        // every tweet found. Data retrieved are based on the xml twitter structure defined
        // as data model (twitter api)
        XmlRole { name: "statusText"; query: "content/string()" }
        XmlRole { name: "timestamp"; query: "published/string()" }
        XmlRole { name: "source"; query: "twitter:source/string()" }
        XmlRole { name: "name"; query: "author/name/string()" }
        XmlRole { name: "userImage"; query: "link[@rel = 'image']/@href/string()" }
    }
}
